<!DOCTYPE html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    
    <title>II: Hugo 目录组织 | Go Learning</title>
    <meta name="viewport" content="width=device-width,minimum-scale=1">
    <meta name="generator" content="Hugo 0.74.3" />
    
    
      <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> 
    
    
      <link href="/dist/css/app.4fc0b62e4b82c997bb0041217cd6b979.css" rel="stylesheet">
    
    
        
        
          
            
    
    
    <link href="/css/main-bundle.css" rel="stylesheet">
    

    
      
<link rel="shortcut icon" href="/assets/micro_xs.png" type="image/x-icon" />

 

    
    
    <meta property="og:title" content="II: Hugo 目录组织" />
<meta property="og:description" content="坚果的 Hugo 教程" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://jimbowhy.gitee.io/tutorials/ch02-project-directories/" />
<meta property="article:published_time" content="2020-08-06T20:14:08-04:00" />
<meta property="article:modified_time" content="2020-08-06T20:14:08-04:00" />
<meta itemprop="name" content="II: Hugo 目录组织">
<meta itemprop="description" content="坚果的 Hugo 教程">
<meta itemprop="datePublished" content="2020-08-06T20:14:08-04:00" />
<meta itemprop="dateModified" content="2020-08-06T20:14:08-04:00" />
<meta itemprop="wordCount" content="746">



<meta itemprop="keywords" content="hugo,menu," />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="II: Hugo 目录组织"/>
<meta name="twitter:description" content="坚果的 Hugo 教程"/>

	
  </head>

  <body class="ma0 avenir bg-near-white">

    
   
  






  <header>
    <div class="bg-black">
      

<nav class="pv3 ph3 ph4-ns" role="navigation">
  <div class="flex-l justify-between items-center center">

    <a href="/" class="logo f3 fw2 hover-white no-underline white-90 dib">
      
        <img src="/assets/micro_xs.png" class="w100 mw5-ns" alt="Go Learning" />
      
    </a>

    <div class="flex-l items-center">
      

      
        <ul class="pl0 mr3">
           

          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline  white-90" href="/tutorials/" title="Hugo 教程 page">
              Hugo 教程
            </a>
          </li>       

          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline  white-90" href="/about/" title="关于 page">
              关于
            </a>
          </li>     

          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline  white-90" href="/post/" title="小说 page">
              小说
            </a>
          </li>     

          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline  white-90" href="/contact/" title="联络 page">
              联络
            </a>
          </li>  
        </ul>
      
      







<a href="https://www.linkedin.com/in/jimboyeah/?zh" target="_blank" class="link-transition linkedin link dib z-999 pt3 pt0-l mr1" title="LinkedIn link" rel="noopener" aria-label="follow on LinkedIn——Opens in a new window">
  <svg  height="32px"  style="enable-background:new 0 0 65 65;" version="1.1" viewBox="0 0 65 65" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <path d="M50.837,48.137V36.425c0-6.275-3.35-9.195-7.816-9.195  c-3.604,0-5.219,1.983-6.119,3.374V27.71h-6.79c0.09,1.917,0,20.427,0,20.427h6.79V36.729c0-0.609,0.044-1.219,0.224-1.655  c0.49-1.22,1.607-2.483,3.482-2.483c2.458,0,3.44,1.873,3.44,4.618v10.929H50.837z M22.959,24.922c2.367,0,3.842-1.57,3.842-3.531  c-0.044-2.003-1.475-3.528-3.797-3.528s-3.841,1.524-3.841,3.528c0,1.961,1.474,3.531,3.753,3.531H22.959z M34,64  C17.432,64,4,50.568,4,34C4,17.431,17.432,4,34,4s30,13.431,30,30C64,50.568,50.568,64,34,64z M26.354,48.137V27.71h-6.789v20.427  H26.354z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/>
</svg>

<span class="new-window"><svg  height="8px"  style="enable-background:new 0 0 1000 1000;" version="1.1" viewBox="0 0 1000 1000" width="8px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<path d="M598 128h298v298h-86v-152l-418 418-60-60 418-418h-152v-86zM810 810v-298h86v298c0 46-40 86-86 86h-596c-48 0-86-40-86-86v-596c0-46 38-86 86-86h298v86h-298v596h596z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/>
</svg>
</span></a>


<a href="https://github.com/jimboyeah/jimboyeah.github.io" target="_blank" class="link-transition github link dib z-999 pt3 pt0-l mr1" title="Github link" rel="noopener" aria-label="follow on Github——Opens in a new window">
  <svg  height="32px"  style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
  <path d="M256,32C132.3,32,32,134.8,32,261.7c0,101.5,64.2,187.5,153.2,217.9c11.2,2.1,15.3-5,15.3-11.1   c0-5.5-0.2-19.9-0.3-39.1c-62.3,13.9-75.5-30.8-75.5-30.8c-10.2-26.5-24.9-33.6-24.9-33.6c-20.3-14.3,1.5-14,1.5-14   c22.5,1.6,34.3,23.7,34.3,23.7c20,35.1,52.4,25,65.2,19.1c2-14.8,7.8-25,14.2-30.7c-49.7-5.8-102-25.5-102-113.5   c0-25.1,8.7-45.6,23-61.6c-2.3-5.8-10-29.2,2.2-60.8c0,0,18.8-6.2,61.6,23.5c17.9-5.1,37-7.6,56.1-7.7c19,0.1,38.2,2.6,56.1,7.7   c42.8-29.7,61.5-23.5,61.5-23.5c12.2,31.6,4.5,55,2.2,60.8c14.3,16.1,23,36.6,23,61.6c0,88.2-52.4,107.6-102.3,113.3   c8,7.1,15.2,21.1,15.2,42.5c0,30.7-0.3,55.5-0.3,63c0,6.1,4,13.3,15.4,11C415.9,449.1,480,363.1,480,261.7   C480,134.8,379.7,32,256,32z"/>
</svg>

<span class="new-window"><svg  height="8px"  style="enable-background:new 0 0 1000 1000;" version="1.1" viewBox="0 0 1000 1000" width="8px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<path d="M598 128h298v298h-86v-152l-418 418-60-60 418-418h-152v-86zM810 810v-298h86v298c0 46-40 86-86 86h-596c-48 0-86-40-86-86v-596c0-46 38-86 86-86h298v86h-298v596h596z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/>
</svg>
</span></a>








    </div>

  </div>
</nav>

    </div>
  </header>




    

    <main class="pb5" role="main">
      
  
  
  <article class="flex-l flex-wrap justify-between mw8 center ph3">
    <header class="mt4 w-100">
      <aside class="instapaper_ignoref b helvetica tracked">
          
        HUGO 教程
      </aside>
      




  <div id="sharing" class="mt3">

    
    <a href="https://www.facebook.com/sharer.php?u=https://jimbowhy.gitee.io/tutorials/ch02-project-directories/" class="facebook no-underline" aria-label="share on Facebook">
      <svg height="32px"  style="enable-background:new 0 0 67 67;" version="1.1" viewBox="0 0 67 67" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M28.765,50.32h6.744V33.998h4.499l0.596-5.624h-5.095  l0.007-2.816c0-1.466,0.14-2.253,2.244-2.253h2.812V17.68h-4.5c-5.405,0-7.307,2.729-7.307,7.317v3.377h-3.369v5.625h3.369V50.32z   M33,64C16.432,64,3,50.569,3,34S16.432,4,33,4s30,13.431,30,30S49.568,64,33,64z" style="fill-rule:evenodd;clip-rule:evenodd;"/></svg>

    </a>

    
    
    <a href="https://twitter.com/share?url=https://jimbowhy.gitee.io/tutorials/ch02-project-directories/&amp;text=II:%20Hugo%20%e7%9b%ae%e5%bd%95%e7%bb%84%e7%bb%87" class="twitter no-underline" aria-label="share on Twitter">
      <svg height="32px"  style="enable-background:new 0 0 67 67;" version="1.1" viewBox="0 0 67 67" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M37.167,22.283c-2.619,0.953-4.274,3.411-4.086,6.101  l0.063,1.038l-1.048-0.127c-3.813-0.487-7.145-2.139-9.974-4.915l-1.383-1.377l-0.356,1.017c-0.754,2.267-0.272,4.661,1.299,6.271  c0.838,0.89,0.649,1.017-0.796,0.487c-0.503-0.169-0.943-0.296-0.985-0.233c-0.146,0.149,0.356,2.076,0.754,2.839  c0.545,1.06,1.655,2.097,2.871,2.712l1.027,0.487l-1.215,0.021c-1.173,0-1.215,0.021-1.089,0.467  c0.419,1.377,2.074,2.839,3.918,3.475l1.299,0.444l-1.131,0.678c-1.676,0.976-3.646,1.526-5.616,1.568  C19.775,43.256,19,43.341,19,43.405c0,0.211,2.557,1.397,4.044,1.864c4.463,1.377,9.765,0.783,13.746-1.568  c2.829-1.673,5.657-5,6.978-8.221c0.713-1.716,1.425-4.851,1.425-6.354c0-0.975,0.063-1.102,1.236-2.267  c0.692-0.678,1.341-1.419,1.467-1.631c0.21-0.403,0.188-0.403-0.88-0.043c-1.781,0.636-2.033,0.551-1.152-0.402  c0.649-0.678,1.425-1.907,1.425-2.267c0-0.063-0.314,0.042-0.671,0.233c-0.377,0.212-1.215,0.53-1.844,0.72l-1.131,0.361l-1.027-0.7  c-0.566-0.381-1.361-0.805-1.781-0.932C39.766,21.902,38.131,21.944,37.167,22.283z M33,64C16.432,64,3,50.569,3,34S16.432,4,33,4  s30,13.431,30,30S49.568,64,33,64z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/></svg>

    </a>

    
    <a href="https://www.linkedin.com/shareArticle?mini=true&amp;url=https://jimbowhy.gitee.io/tutorials/ch02-project-directories/&amp;title=II:%20Hugo%20%e7%9b%ae%e5%bd%95%e7%bb%84%e7%bb%87" class="linkedin no-underline" aria-label="share on LinkedIn">
      <svg  height="32px"  style="enable-background:new 0 0 65 65;" version="1.1" viewBox="0 0 65 65" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <path d="M50.837,48.137V36.425c0-6.275-3.35-9.195-7.816-9.195  c-3.604,0-5.219,1.983-6.119,3.374V27.71h-6.79c0.09,1.917,0,20.427,0,20.427h6.79V36.729c0-0.609,0.044-1.219,0.224-1.655  c0.49-1.22,1.607-2.483,3.482-2.483c2.458,0,3.44,1.873,3.44,4.618v10.929H50.837z M22.959,24.922c2.367,0,3.842-1.57,3.842-3.531  c-0.044-2.003-1.475-3.528-3.797-3.528s-3.841,1.524-3.841,3.528c0,1.961,1.474,3.531,3.753,3.531H22.959z M34,64  C17.432,64,4,50.568,4,34C4,17.431,17.432,4,34,4s30,13.431,30,30C64,50.568,50.568,64,34,64z M26.354,48.137V27.71h-6.789v20.427  H26.354z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/>
</svg>

    </a>
  </div>


      <h1 class="f3 athelas mt3 mb1">II: Hugo 目录组织</h1>
      
      
      <time class="f6 mv4 dib tracked" datetime="2020-08-06T20:14:08-04:00">August 6, 2020</time>

      
      
    </header>

    <div class="nested-copy-line-height lh-copy serif f5 nested-links nested-img mid-gray pr4-l w-two-thirds-l">
       
      <a title="Prev Post" class="prev fl" href="https://jimbowhy.gitee.io/tutorials/ch03-hugo-modules/">III: Hugo Modules 模块</a>
      
       
      <a title="Next Post" class="next fr" href="https://jimbowhy.gitee.io/tutorials/ch01-hugo-web-framework/">I: Hugo Web Framework</a>
      
      <p class="cf"></p>

      <p>目录：</p>
<div class="contents"><a href="#archetypes-目录">## archetypes 目录</a><br><a href="#assets-目录">## assets 目录</a><br><a href="#config-目录">## config 目录</a><br><a href="#content-目录">## content 目录</a><br><a href="#data-目录">## data 目录</a><br><a href="#layouts-目录">## layouts 目录</a><br><a href="#static-目录">## static 目录</a><br><a href="#resources-目录">## resources 目录</a><br><a href="#public-目录">## public 目录</a><br></div>
<p>Hugo 仓库提供的文档项目本身就是一个很好的示范，以下内容摘自下面文档：</p>
<pre><code>hugo\docs\content\en\getting-started\quick-start.md
</code></pre>
<p>使用 <strong>hugo new site</strong> 生成的项目模板目录结构：</p>
<pre><code>.
├── archetypes 
├── config.toml
├── content
├── data
├── layouts
├── static
└── themes
</code></pre>
<h2 id="archetypes-目录">archetypes 目录</h2>
<p>默认，通过 <code>hugo new</code> 创建的内容会添加 <code>date</code>, <code>title</code>, <code>draft = true</code> 等扉页 front matter 设置信息，它们就是从 <strong>archetypes</strong> 模板文件中拷贝的。这可以节省时间，同时保证统一性。</p>
<p><strong>Archetypes</strong> 作为内容模板，Hugo 官方建议静态站点源码文件按 section 组织，每个 section 使用相应同名的 archetypes，这样 section 下面的 .md 就会自动使用响应 type 的 meta data。</p>
<p>当执行 <strong>hugo new posts/dmeo.md</strong>，Hugo 会到 archetypes 目录下搜索 <strong>posts.md</strong> 文件，找到哪个则使用哪个内容模板：</p>
<ul>
<li><code>archetypes/posts.md</code></li>
<li><code>archetypes/default.md</code></li>
<li><code>themes/my-theme/archetypes/posts.md</code></li>
<li><code>themes/my-theme/archetypes/default.md</code></li>
</ul>
<p>要明确一点，Hugo 中 MD 文件一般是作为内容文件使用的，只有特殊位置中的 MD 文件才是内容模板，而 <strong>layouts</strong> 目录才是模板存放的专用位置。</p>
<h2 id="assets-目录">assets 目录</h2>
<p>不是默认创建的资源目录，保存所有需要通过 <strong>Hugo Pipes</strong> 处理的资源，只有那些 <code>.Permalink</code> 和 <code>.RelPermalink</code> 引用的文件会发布到 <code>public</code> 目录中，参考 Hugo 管道处理。</p>
<h2 id="config-目录">config 目录</h2>
<p>配置目录，非默认创建，Hugo 有大量的配置指令，此目录用于保存 JSON, YAML, TOML 等配置文件。最简单的项目只需要一个根目录下的配置文件 <code>config.toml</code>。 Every root setting object can stand as its own file and structured by environments.</p>
<ul>
<li>每个配置文件代表一个配置根对象 configuration root object，如 <code>Params</code>, <code>Menus</code>, <code>Languages</code> 等等。</li>
<li>每个目录保存一组配置文件，针对独一的环境提供设置。</li>
<li>文件可以本地化为特定语言。</li>
</ul>
<p>参考以下的配置文件目录结构：</p>
<pre><code>├── config
│   ├── _default
│   │   ├── config.toml
│   │   ├── languages.toml
│   │   ├── menus.en.toml
│   │   ├── menus.zh.toml
│   │   └── params.toml
│   ├── production
│   │   ├── config.toml
│   │   └── params.toml
│   └── staging
│       ├── config.toml
│       └── params.toml
</code></pre>
<p>当运行 <code>hugo --environment staging</code>，Hugo 会将 <code>config/_default</code> 合并到 <code>staging</code>。</p>
<p>开发中默认环境为 <strong>development</strong> 即对应 <code>hugo serve</code> 运行命令，而编译生成时的环境为 <strong>production</strong> 对应 <code>hugo</code> 命令，参考 configuration.md 文档。</p>
<p>内容目录可以根据语言设置来调整，以下是 Hugo 文档中的 <strong>_default\languages.toml</strong> 配置：</p>
<pre><code>  [en]
    contentDir = &quot;content/en&quot;
    languageName = &quot;English&quot;
    weight = 1
  
  [zh]
    contentDir = &quot;content/zh&quot;
    languageName = &quot;中文&quot;
    weight = 2
</code></pre>
<p>多语言支持参考 multilingual.md 文档。</p>
<h2 id="content-目录">content 目录</h2>
<p>参考内容管理 types.md, organization 文档。</p>
<p>所有内容页面存放目录，content 下的一级子目录看作一个对应的 <strong>section</strong> 内容分类区 content section。比如，为博客设置一个 <code>blog</code> 目录，为文章设置一个 <code>articles</code> 目录，为教程设置一个 <code>tutorials</code> 目录等，Hugo 使用内容分类区分作为默认<strong>内容类型</strong> content type，如果在扉页 front matter 设置了 <code>type</code> 则以具体设置的类型为准。</p>
<p>内容目录结构与 URL 对应关系参考：</p>
<pre><code>.
└── content
    └── about
    |   └── index.md       // &lt;- https://example.com/about/
    ├── posts
    |   ├── _index.md      // &lt;- https://example.com/posts/
    |   ├── index.md       // &lt;- https://example.com/posts/
    |   ├── firstpost.md   // &lt;- https://example.com/posts/firstpost/
    |   ├── happy
    |   |   └── ness.md    // &lt;- https://example.com/posts/happy/ness/
    |   └── secondpost.md  // &lt;- https://example.com/posts/secondpost/
    └── quote
        ├── first.md       // &lt;- https://example.com/quote/first/
        └── second.md      // &lt;- https://example.com/quote/second/
</code></pre>
<p>每个目录下的 <strong>_index.md</strong> 和 <strong>index.md</strong> 是特殊的索引页面，二选一使用。可以在其扉页 front matter 为模板提供元数据，如 list templates, section templates, taxonomy templates, taxonomy terms templates, homepage template 等等。</p>
<p>在模板文件中，可以使用 <strong>.Site.GetPage</strong> 函数来获取数据。</p>
<p>而 <strong>index.md</strong> 页面呈现是较特殊的一个，假设在 section 目录下无其它 md 文件时，默认就展现 index.md 页面。如果，包含其它页面，那么就会在列表中展示 index.md，但默认它就是链接到列表本身。</p>
<p>例如，Hugo 文档中的 <strong>_index.md</strong> 示范，title 和 description 这些数据就会在列表页面模板中呈现出来：</p>
<pre><code>---
title: Get Started
linktitle: Get Started Overview
description: Quick start and guides for installing Hugo on your preferred operating system.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
categories: [getting started]
keywords: [usage,docs]
menu:
  docs:
    parent: &quot;getting-started&quot;
    weight: 1
weight: 0001    #rem
draft: false
aliases: [/overview/introduction/]
toc: false
---

If this is your first time using Hugo and you've [already installed Hugo on your machine][installed], we recommend the [quick start][]. You can also use [external learning resources][] to learn Hugo.

[installed]: /getting-started/installing/
[quick start]: /getting-started/quick-start/
[external learning resources]: /getting-started/external-learning-resources/
</code></pre>
<p>参考各种列表模板文件的使用：</p>
<ul>
<li>分类术语页 Taxonomy terms pages</li>
<li>分类列表页 Taxonomy list pages</li>
<li>分区列表页 Section list pages</li>
<li>简易信息聚合 RSS - Really Simple Syndication</li>
</ul>
<h2 id="data-目录">data 目录</h2>
<p>数据模板目录，Hugo 静态网站不会连接像 MySQL 这样的数据库，而此目录保存的数据相当于 Hugo 使用的数据库，生成过程用到的配置数据，可以用 YAML, JSON, TOML 等格式文件。数据模板除了在此的文件定义，还可以从动态内容中生成。通过 <strong>getJSON</strong> 和 <strong>getCSV</strong> 两个函数是模板函数加载外部数据，或者访问数据接口，在外部数据加载完成以前，Hugo 会暂停渲染模板文件。</p>
<pre><code>{{ $dataJ := getJSON &quot;url&quot; }}
{{ $dataC := getCSV &quot;separator&quot; &quot;url&quot; }}
{{ $dataJ := getJSON &quot;url prefix&quot; &quot;arg1&quot; &quot;arg2&quot; &quot;arg n&quot; }}
{{ $dataC := getCSV  &quot;separator&quot; &quot;url prefix&quot; &quot;arg1&quot; &quot;arg2&quot; &quot;arg n&quot; }}
</code></pre>
<p>假设 <code>data/jazz/bass/jacopastorius.toml</code> 数据模板文件包含如下贝斯手数据：</p>
<pre><code>discography = [
&quot;1974 – Modern American Music … Period! The Criteria Sessions&quot;,
&quot;1974 – Jaco&quot;,
&quot;1976 - Jaco Pastorius&quot;,
&quot;1981 - Word of Mouth&quot;,
&quot;1981 - The Birthday Concert (released in 1995)&quot;,
&quot;1982 - Twins I &amp; II (released in 1999)&quot;,
&quot;1983 - Invitation&quot;,
&quot;1986 - Broadway Blues (released in 1998)&quot;,
&quot;1986 - Honestly Solo Live (released in 1990)&quot;,
&quot;1986 - Live In Italy (released in 1991)&quot;,
&quot;1986 - Heavy'n Jazz (released in 1992)&quot;,
&quot;1991 - Live In New York City, Volumes 1-7.&quot;,
&quot;1999 - Rare Collection (compilation)&quot;,
&quot;2003 - Punk Jazz: The Jaco Pastorius Anthology (compilation)&quot;,
&quot;2007 - The Essential Jaco Pastorius (compilation)&quot;
]
</code></pre>
<p>那么，可以通过 <code>.Site.Data.jazz.bass.jacopastorius</code> 来使用它，在模板中将数据列表渲染出来：</p>
<pre><code>{{ range $.Site.Data.jazz.bass }}
   {{ partial &quot;artist.html&quot; . }}
{{ end }}
</code></pre>
<p>然后在 <code>partials/artist.html</code>:</p>
<pre><code>&lt;ul&gt;
{{ range .discography }}
  &lt;li&gt;{{ . }}&lt;/li&gt;
{{ end }}
&lt;/ul&gt;
</code></pre>
<h2 id="layouts-目录">layouts 目录</h2>
<p>布局模板文件目录，存放 <code>.html</code> 布局模板文件，对应不同的内容，模板有多种，data-templates、homepage、lists、menu-templates、partials、section-templates 等等。</p>
<p>站点的首页模板在主题目录中 <strong>layouts/index.html</strong>，除首页外，Hugo 有两类基本页面：</p>
<ul>
<li>Single page 单体页面，如 <strong>hugo new demo.md</strong> 创建的 Post 页面；</li>
<li>List page 列表页面，如 tags 或 categories 页面；</li>
</ul>
<p>这两种页面的默认模板都在主题目录中 <strong>layouts/_default</strong>，分别对应着 single.html 和 list.html。参考单页面内容模板 single-page-templates.md 和 lists.md 文档。</p>
<p>项目源码文件的目录布局影响着最终生成的 HTML 文件的结构布局，通常分成若干个部分，每部分都用一个目录管理，比如 content 下的 posts 目录对应所有 post 页面。编译后生成的 .html 文件也会在 public 的 posts 目录下，那么这里的 <strong>posts</strong> 就是一个 <strong>section</strong> 概念。</p>
<p>Hugo 会为每个 section 生成 index.html，采用主题布局中的 index.html 模板。</p>
<p>至于是否采用 <strong>layouts/_default/list.html</strong>，这要看 host 的匹配顺序，官方给出的布局模板匹配参考顺序：</p>
<pre><code>/layouts/section/SECTION.html
/layouts/_default/section.html
/layouts/_default/list.html
/themes/THEME/layouts/section/SECTION.html
/themes/THEME/layouts/_default/section.html
/themes/THEME/layouts/_default/list.html
</code></pre>
<p>这个例子中 THEME=ananke, SECTION=posts，如果根目录下的 layouts 是空的，就进入主题目录下搜索 <strong>layouts/section/posts.html</strong> 模板，如果也不存在，因此用的是主题目录下的 <strong>_default/list.html</strong>。</p>
<h2 id="static-目录">static 目录</h2>
<p>静态资源存放目录，比如想使用 Marmarid 画作模块，或者 jQuery 工具库，或者其它脚本、图像、CSS 等等，就可以将文件放到这里，在 Hugo 编译生成时会自动原样复制到 <strong>public</strong> 目录。注意，可以有多个静态资源目录。</p>
<h2 id="resources-目录">resources 目录</h2>
<p>资源缓冲目录，非默认创建，用于加速 Hugo 的生成过程，也可以用给模板作者分发构建好的 SASS 文件，因此不必安装预处理器。</p>
<h2 id="public-目录">public 目录</h2>
<p>生成静态站点的文件输出目录。</p>
 
      <a title="Prev Post" class="prev fl" href="https://jimbowhy.gitee.io/tutorials/ch03-hugo-modules/">III: Hugo Modules 模块</a>
      
       
      <a title="Next Post" class="next fr" href="https://jimbowhy.gitee.io/tutorials/ch01-hugo-web-framework/">I: Hugo Web Framework</a>
      
      <p class="cf"></p><ul class="pa0">
  
   <li class="list">
     <a href="/tags/hugo" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif">hugo</a>
   </li>
  
   <li class="list">
     <a href="/tags/menu" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif">menu</a>
   </li>
  
</ul>
<div class="mt3 instapaper_ignoref">
      
      
      </div>
    </div>

    <aside class="w-30-l mt6-l">




  <div class="bg-light-gray pa3 nested-list-reset nested-copy-line-height nested-links">
    <p class="f5 b mb3">相关內容</p>
    <ul class="pa0 list">
	   
	     <li  class="mb2">
          <a href="/tutorials/ch05a-hugo-templates/">V: Templates 模板机制</a>
        </li>
	    
	     <li  class="mb2">
          <a href="/tutorials/ch07-varialbes/">VII: Variables 对象变量</a>
        </li>
	    
	     <li  class="mb2">
          <a href="/tutorials/ch05b-hugo-templates/">V: Templates 其它模板</a>
        </li>
	    
	     <li  class="mb2">
          <a href="/tutorials/ch09-menus/">IX: Menus 菜单组织</a>
        </li>
	    
	     <li  class="mb2">
          <a href="/tutorials/ch03-hugo-modules/">III: Hugo Modules 模块</a>
        </li>
	    
	     <li  class="mb2">
          <a href="/tutorials/ch01-hugo-web-framework/">I: Hugo Web Framework</a>
        </li>
	    
	     <li  class="mb2">
          <a href="/tutorials/ch04-hugo-pipes/">IV: Hugo Pipes 管道处理</a>
        </li>
	    
	     <li  class="mb2">
          <a href="/tutorials/ch06-multilingual/">VI: Multilingual 多语言支持</a>
        </li>
	    
	     <li  class="mb2">
          <a href="/tutorials/ch08-functions/">VIII: Functions 内置函数</a>
        </li>
	    
    </ul>
</div>

</aside>

  </article>

    </main>

    <footer class="bg-black bottom-0 w-100 pa3" role="contentinfo">
  <div class="flex justify-between">
  <a class="f4 fw4 hover-white no-underline white-70 dn dib-ns pv2 ph3" href="https://jimbowhy.gitee.io/" >
    &copy;  Nothing is Mine 2021 
  </a>
    <div>







<a href="https://www.linkedin.com/in/jimboyeah/?zh" target="_blank" class="link-transition linkedin link dib z-999 pt3 pt0-l mr1" title="LinkedIn link" rel="noopener" aria-label="follow on LinkedIn——Opens in a new window">
  <svg  height="32px"  style="enable-background:new 0 0 65 65;" version="1.1" viewBox="0 0 65 65" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <path d="M50.837,48.137V36.425c0-6.275-3.35-9.195-7.816-9.195  c-3.604,0-5.219,1.983-6.119,3.374V27.71h-6.79c0.09,1.917,0,20.427,0,20.427h6.79V36.729c0-0.609,0.044-1.219,0.224-1.655  c0.49-1.22,1.607-2.483,3.482-2.483c2.458,0,3.44,1.873,3.44,4.618v10.929H50.837z M22.959,24.922c2.367,0,3.842-1.57,3.842-3.531  c-0.044-2.003-1.475-3.528-3.797-3.528s-3.841,1.524-3.841,3.528c0,1.961,1.474,3.531,3.753,3.531H22.959z M34,64  C17.432,64,4,50.568,4,34C4,17.431,17.432,4,34,4s30,13.431,30,30C64,50.568,50.568,64,34,64z M26.354,48.137V27.71h-6.789v20.427  H26.354z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/>
</svg>

<span class="new-window"><svg  height="8px"  style="enable-background:new 0 0 1000 1000;" version="1.1" viewBox="0 0 1000 1000" width="8px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<path d="M598 128h298v298h-86v-152l-418 418-60-60 418-418h-152v-86zM810 810v-298h86v298c0 46-40 86-86 86h-596c-48 0-86-40-86-86v-596c0-46 38-86 86-86h298v86h-298v596h596z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/>
</svg>
</span></a>


<a href="https://github.com/jimboyeah/jimboyeah.github.io" target="_blank" class="link-transition github link dib z-999 pt3 pt0-l mr1" title="Github link" rel="noopener" aria-label="follow on Github——Opens in a new window">
  <svg  height="32px"  style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
  <path d="M256,32C132.3,32,32,134.8,32,261.7c0,101.5,64.2,187.5,153.2,217.9c11.2,2.1,15.3-5,15.3-11.1   c0-5.5-0.2-19.9-0.3-39.1c-62.3,13.9-75.5-30.8-75.5-30.8c-10.2-26.5-24.9-33.6-24.9-33.6c-20.3-14.3,1.5-14,1.5-14   c22.5,1.6,34.3,23.7,34.3,23.7c20,35.1,52.4,25,65.2,19.1c2-14.8,7.8-25,14.2-30.7c-49.7-5.8-102-25.5-102-113.5   c0-25.1,8.7-45.6,23-61.6c-2.3-5.8-10-29.2,2.2-60.8c0,0,18.8-6.2,61.6,23.5c17.9-5.1,37-7.6,56.1-7.7c19,0.1,38.2,2.6,56.1,7.7   c42.8-29.7,61.5-23.5,61.5-23.5c12.2,31.6,4.5,55,2.2,60.8c14.3,16.1,23,36.6,23,61.6c0,88.2-52.4,107.6-102.3,113.3   c8,7.1,15.2,21.1,15.2,42.5c0,30.7-0.3,55.5-0.3,63c0,6.1,4,13.3,15.4,11C415.9,449.1,480,363.1,480,261.7   C480,134.8,379.7,32,256,32z"/>
</svg>

<span class="new-window"><svg  height="8px"  style="enable-background:new 0 0 1000 1000;" version="1.1" viewBox="0 0 1000 1000" width="8px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<path d="M598 128h298v298h-86v-152l-418 418-60-60 418-418h-152v-86zM810 810v-298h86v298c0 46-40 86-86 86h-596c-48 0-86-40-86-86v-596c0-46 38-86 86-86h298v86h-298v596h596z" style="fill-rule:evenodd;clip-rule:evenodd;fill:;"/>
</svg>
</span></a>







</div>
  </div>
</footer>

    

  <script src="/dist/js/app.3fc0f988d21662902933.js"></script>


  </body>
</html>
